<%@ page import="java.io.*, java.text.*, java.util.Date, java.sql.*, javax.servlet.*, javax.servlet.http.*, java.util.*" %>
<%
String usernameSC = (String) session.getAttribute("session_name");
String typeSC = (String) session.getAttribute("type");
String idS = (String) session.getAttribute("id");
if(usernameSC != null && typeSC.equals("student"))
{
	String pid = request.getParameter("pId");
	String driver ="com.mysql.jdbc.Driver";
	String url = "jdbc:mysql://localhost:3306/projects";
	String username = "ia";
	String password = "123";
	String query;
	String query1;
	int size = 0;
	int id = 0;

	try
	{
		Class.forName(driver).newInstance();
		Connection connection = DriverManager.getConnection(url, username, password);
		Statement statement = connection.createStatement();
		Statement statement1 = connection.createStatement();	
		
		query1 = "select ref_id from user_log_in where id =" + idS;
		ResultSet rs1 = statement.executeQuery(query1);
		if(rs1.next())
		{
			id = rs1.getInt(1);
		}	
		query = "DELETE FROM join_in WHERE st_id = "+id+" and proj_id= "+pid;
		statement1.executeUpdate(query);
		connection.close();
		
	}catch(ClassNotFoundException cnfe)
	{
		out.println("<br>Couldn't find class file" + cnfe); 
	}catch(SQLException sqle)
	{
		out.println("<br>SQL Exception: " + sqle);
	}catch(InstantiationException ie)
	{
		out.println("<br>Instant exception : " + ie);
	}catch(IllegalAccessException iae)
	{
		out.println("<br>Illegal access exception : " + iae);
	}
	response.sendRedirect("index.jsp");
}
else
	response.sendRedirect("error.jsp");
%>